package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.constant.RoleType;
import com.cloudfun.campusshare.common.model.vo.ReplenishLogVO;
import com.cloudfun.campusshare.common.model.vo.ReplenishSettingVO;
import com.cloudfun.campusshare.common.model.vo.ReplenishVO;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.service.ReplenishService;
import com.cloudfun.campusshare.service.WashPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author wangxiyuan
 * @description
 * @createDate 2021/5/18 18:37
 **/
@RestController
@RequestMapping("/v1/replenish")
@Api(value = "补货模块", description = "补货模块")
@Slf4j
@AuthRequired(role = {RoleType.OPERATIONAL_MERCHANT, RoleType.ADMIN,RoleType.REPLENISH})
public class ReplenishController {
    @Autowired
    private WashPointService washPointService;

    @Autowired
    private ReplenishService replenishService;

    @ApiOperation(value = "当selectKey = 1 获取所有运营商的值；selectKey =2，获取所有场地名称的值;当selectKey =2，value传归属运营商的id时，获得所有对应场地名称", notes = "下拉选列表详情获取")
    @RequestMapping(value = "/getSelectInfo", method = RequestMethod.POST)
    public BaseResult getSelectInfo(@ApiParam(value = "下拉选键值,运营商or场地，1为运营商，2为场地")String selectKey,@ApiParam(value = "下拉选值(不传值获取运营商下拉选，传递运营商洗衣点的值，获取对应的场地)")String value) {
        return washPointService.getSelectInfo(selectKey,value);
    }

    @ApiOperation(value = "补货列表查询", notes = "补货列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public BaseResult list(@RequestBody ReplenishVO replenishVO) {
        return replenishService.list(replenishVO);
    }

    @ApiOperation(value = "更新库存", notes = "更新库存")
    @GetMapping(value = "/updateStock")
    public BaseResult updateStock(@ApiParam(value = "设备识别码") String imei,
                                  @ApiParam(value = "洗衣液传1，消毒液传2")Integer liquidType,
                                  @ApiParam(value = "加液量") Integer size){
        return replenishService.updateStock(imei,liquidType,size);
    }

    @ApiOperation(value = "补货日志列表查询", notes = "补货日志列表查询")
    @RequestMapping(value = "/log/list", method = RequestMethod.POST)
    public BaseResult logList(@RequestBody ReplenishLogVO replenishVO) {
        return replenishService.logList(replenishVO);
    }

    @ApiOperation(value = "补货日志列表导出", notes = "补货日志列表导出")
    @RequestMapping(value = "/log/export", method = RequestMethod.POST)
    public BaseResult logExport(@RequestBody ReplenishLogVO replenishVO, HttpServletResponse response) {
        return replenishService.logExport(replenishVO,response);
    }

    @ApiOperation(value = "补货列表按状态统计", notes = "补货列表按状态统计")
    @GetMapping(value = "/status/count")
    public BaseResult statusCount(@ApiParam(value = "设备类型") String deviceType,
                                  @ApiParam(value = "补货状态") Integer replenishStatus) {
        return replenishService.statusCount(deviceType,replenishStatus);
    }

    @ApiOperation(value = "进入阈值管理页面", notes = "进入阈值管理页面")
    @GetMapping(value = "/setting/page")
    public BaseResult settingPage(String washPointId) {
        return replenishService.settingPage(washPointId);
    }

    @ApiOperation(value = "加液泵容量设置", notes = "加液泵容量设置")
    @PostMapping(value = "/size/setting")
    public BaseResult setting(@RequestBody ReplenishSettingVO settingVO) {
        return replenishService.setting(settingVO);
    }
}
